package com.oocl.zero.task0710;

import java.util.Set;

import com.oocl.zero.task0710.property.entity.Customer;
import com.oocl.zero.task0710.property.filter.CustomerFilter;
import com.oocl.zero.task0710.property.in.Input;
import com.oocl.zero.task0710.property.out.Printer;
import com.oocl.zero.task0710.property.parse.Parser;
import com.oocl.zero.task0710.property.parse.impl.ParserImpl;
import com.oocl.zero.task0710.property.store.CustomerStore;
import com.oocl.zero.task0710.property.util.CustomerUtil;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
        Input in=new Input("data.txt");
        Parser p=new ParserImpl();
        CustomerFilter f=new CustomerFilter();
        CustomerStore store=new CustomerStore();
        String parseContent;
        
        while(in.hasNext()){
        	parseContent = in.nextLine();
        	p.doParse(parseContent);
        	f.doFilter(p.getDataMap());
        	
//        	System.out.println(p.getDataMap().size());
        	
        	if(!f.isErr()){
        		Customer c = CustomerUtil.getCustomerInstanceBy(p.getDataMap());
        		if(c!=null){
        			store.getSet().add(c);
        		}
        	}else{
        		Printer.print("input data:"+parseContent);
        		Printer.newLine();
        	}
        }
        
        //sort by id
        Printer.print("sort by id:");
        Set<Customer> rsSet = store.sortById();
        for (Customer c : rsSet) {
			Printer.print(c);
		}
        Printer.newLine();
        
        //sort by birth
        Printer.print("sort by birth:");
        rsSet = store.sortByBirthday();
        for (Customer c : rsSet) {
			Printer.print(c);
		}
        Printer.newLine();
        
        //print c in xml style
        Printer.print("print c in xml style:");
        Printer.printCustomerInXMLStyle(store.getSet());
    }
}
